package customer

import (
	"context"
	"github.com/google/wire"
	"sieve_admin_server_userpass/app/api/util"
	"sieve_admin_server_userpass/app/contextx"
	"sieve_admin_server_userpass/app/schema"
	"sieve_admin_server_userpass/app/server"
	serviceCustomer "sieve_admin_server_userpass/app/service/customer"
)

var (
	_         util.API = (*UserAPI)(nil)
	InComeSet          = wire.NewSet(wire.Struct(new(InComeAPI), "*"))
)

type InComeAPI struct {
	util.EmptyAPI
	InComeSrv           *serviceCustomer.InComeSrv
	InComeStatisticsSrv *serviceCustomer.InComeStatisticsSrv
}

func (a *InComeAPI) Cron() {

	_ = a.InComeStatisticsSrv.Cron()
}

func (a *InComeAPI) GetApis() []*server.BatchModTree {
	return []*server.BatchModTree{
		{
			Obj:   a,
			Name:  "income",
			Title: "收益统计", Perms: []*server.Perm{
				{Name: "query", Title: "搜索"},
				{Name: "export", Title: "导出"},
			},
			Order: 7,
		},
	}
}

func (a *InComeAPI) API_query_list(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("id", true),
				contextx.NewVar("business_type_id", true),
				contextx.NewVar("date"),        // eg:2023-03-01,2023-03-31
				contextx.NewVar("leader_name"), // 上级
				contextx.NewVar("account_id"),  // 用户ID
				contextx.NewVar("sieve_source_name"),
			},
		)

		p = schema.PaginationParam{
			PageIndex: util.ToInt(ctx.Args.Get("page_index")),
			PageSize:  util.ToInt(ctx.Args.Get("page_size")),
		}
	)

	return a.InComeSrv.Query(context.Background(), uint64(ctx.Uid), reqArgs, p)
}

func (a *InComeAPI) API_export_list(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("ids"),
			},
		)
	)

	return a.InComeSrv.Export(context.Background(), uint64(ctx.Uid), reqArgs)
}
